/**
 * Label class
 * @type {omplusClass}
 */
Omplus.views.Label = Omplus.base.extend(Omplus.views.Control,{
    init: function(){},

    /**
     * Creates a <label> and adds it to <div> tag from Control
     */
    render : function(){
        var label = jQuery.extend(true, {}, $("<label></label>"));
        label.addClass("label").attr("id", this.omplusName);
        label.text(this.text);
        this.getContent().append(label);
    },

    omplusType : "Label",

    errorable : false,

    text : null,

    getValue : function(){
        return this.getContent().find("label").text();
    },

    setValue : function(newValue){
        if (newValue == null) newValue = "";
        this.getContent().find("label").text(newValue);
    }
});

Omplus.views.Button = Omplus.base.extend(Omplus.views.Control,{
    init: function(){},

    /**
     * Creates a <label> and adds it to <div> tag from Control
     */
    render : function(){
        var button = jQuery.extend(true, {}, $("<button></button>"));
        button.addClass("button").attr("id", this.omplusName);
        $('body').on("click", "#"+this.omplusName, this.click);
        button.text(this.text);
        this.getContent().append(button);
    },

    omplusType : "Button",

    errorable : false,

    text : null,

    click : function(){},

    getValue : function(){
        return this.getContent().find("button").text();
    },

    setValue : function(newValue){
        return this.getContent().find("button").text(newValue);
    },

    destroy:function () {
        if (this.controller)
            Omplus.globals.getObject(this.omplusName + ".OnDestroyView").notify(this.controller);
        for (var i in this.events) {
            delete Omplus.globals.objects[this.omplusName + "." + this.events[i]];
        }
        $('body').off("click", "#"+this.omplusName, this.click);
        delete Omplus.globals.objects[this.omplusName];
    }
});

Omplus.views.ProgressBar = Omplus.base.extend(Omplus.views.Control,{
    /**
     * Creates a <label> and adds it to <div> tag from Control
     */
    render : function(){
        var progressWrapper = jQuery.extend(true, {}, $("<div></div>"));
        progressWrapper.addClass("progressWrapper").attr("id", this.omplusName);
        this.getContent().append(progressWrapper);
        var progressScroller = jQuery.extend(true, {}, $("<div></div>"));
        progressScroller.addClass("progressScroller");
        progressWrapper.append(progressScroller);
    },

    omplusType : "ProgressBar",

    errorable : false,

    text : null,

    click : function(){},

    getValue : function(){
        return this.getContent().find(".progressScroller").width();
    },

    setValue : function(newValue){
        return this.getContent().find(".progressScroller").css({
            width : newValue + "%"
        });
    }
});

Omplus.views.Image = Omplus.base.extend(Omplus.views.Control,{
    init: function(){},

    /**
     * Creates a <label> and adds it to <div> tag from Control
     */
    render : function(){
        var image = jQuery.extend(true, {}, $("<img/>"));
        image.addClass("image").attr("id", this.omplusName);
        this.getContent().append(image);
    },

    omplusType : "Image",

    errorable : false,

    text : null,

    getValue : function(){
        return this.getContent().find("img").attr("src");
    },

    setValue : function(newValue){
        if (newValue == null || newValue == "None") newValue = "";
        this.getContent().find("img").attr("src", newValue);
    }
});